package gtkwire.widget;

import gtkwire.*;
import gtkwire.listener.connector.ToggleListenerFilter;
import gtkwire.listener.ToggleListener;

/**
*A button which retains its state.
*/
public class GtkToggleButton extends GtkButton
{
	private String[] createFlag = null;

	public GtkToggleButton()
	{
		super();
		widgetType = WT_GtkToggleButton;
		createFlag = new String[0];
		gtkCreate();
		createFlag = null;
	}

	public GtkToggleButton( String name, GladeKey key )
	{
		super( name, key );
		widgetType = WT_GtkToggleButton;
	}

	protected String[] getCreateData(){ return createFlag; }
	
	/**
	*Sets the status of the toggle button.
	*/
	public void setPressed( boolean b )
	{
		app().sendCommand( name, GTKWireCommand.SET_ACTIVE, b );
	}

	/**
	*Returns TRUE if the toggle button is pressed in and FALSE if it is raised.
	*/
	public boolean getPressed()
	{
		GTKWireMessage answer = app().sendCommandRequest( name, widgetType, GTKWireCommandRequest.GET_TOGGLED, null );
		return ((Boolean) answer.getMessageObject()).booleanValue();
	}

	/**
	*Adds ToggleListener.
	*/
	public void addToggleListener( ToggleListener listener )
	{
		ToggleListenerFilter tl = new ToggleListenerFilter( listener );
		tl.addFilteringName( name );
		app().addListener( tl );
	}

}//end class
